package com.tmpt.controller.springmvc.handlers;

import com.alibaba.druid.pool.DruidDataSource;
import com.tmpt.controller.jsperreport.JasperHelper;
import com.tmpt.controller.jsperreport.UserReport;
import com.tmpt.controller.springmvc.PageUtils;
import com.tmpt.dto.A2UserDto;
import com.tmpt.dto.Result;
import com.tmpt.service.IOrgService;
import com.tmpt.service.ISecurityV2Service;
import com.tmpt.utils.DateTool;
import com.tmpt.utils.MD5Util;
import com.tmpt.utils.StringUtils;
import com.tmpt.utils.WebUtils;
/*import com.tmptSource.dto.OwNumberInfoDto;
import com.tmptSource.dto.OwOffpostRecordDto;
import com.tmptSource.dto.OwSigninDto;
import com.tmptSource.dto.PageDto;
import com.tmptSource.service.intf.IOwNumberInfoService;
import com.tmptSource.service.intf.IOwOffpostRecordService;
import com.tmptSource.service.intf.IOwSigninService;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;*/
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by wxy on 2017/10/17.
 */

@Controller
@RequestMapping("/springmvc/jreport")
public class JsperReportAction {

    private Logger log = Logger.getLogger(this.getClass());
    @Resource
    private DruidDataSource druidDataSource;

    /*@RequestMapping(value = "/showReport",method = RequestMethod.GET)
    public ModelAndView showReport(ModelMap model,  HttpServletRequest request, HttpSession session){
        List<UserReport> reportList = new ArrayList<UserReport>();
        UserReport report = new UserReport();
        report.setReportname("这是用户报表");
        report.setToday(DateTool.currentDate("yyyy-MM-dd"));
        //report.getImageUrl();
        reportList.add(report);

        JRDataSource jrDataSource = new JRBeanCollectionDataSource(reportList);
        //这里选择html格式，当然也有pdf格式，只是jasperreports对应的解析器不同
        model.addAttribute("format","html");
        //对应配置文件bean的reportDataKey属性
        model.addAttribute("userDataSource",jrDataSource);
        //对应配置文件中bean的name
        return new ModelAndView("jreport",model);
    }*/




    /*@RequestMapping(value = "/showReport")
    public void showReport(String jasperName, HttpServletRequest request, HttpServletResponse response) throws IOException, JRException, SQLException {

        Connection connection = null;
        try {
            connection = druidDataSource.getConnection();
            ServletContext context = request.getSession().getServletContext();
            File reportFile = null;
            reportFile = new File("/files1/bi/jasper/"+jasperName);
            String exportFilePath = "tempPath";
            String fileName = "fileName";

            HashMap map = new HashMap();
            //map.put("loginname",loginname);

                *//* STEP 4 : 输出报表
                *不同输出方式，具体实现在后边注释*//*
                *//*使用HTML输出，表现为页面直接显示报表*//*
            JasperHelper.showHtml(exportFilePath, reportFile.getPath(), request, response, map, connection);
                *//*使用PDF输出，表现为出现PDF文件的下载对话框*//**//*
                JasperHelper.export("pdf", fileName, reportFile, request,
                        response, new HashMap(), connection);
                *//**//*使用EXCEL输出，表现为出现EXCEL文件的下载对话框*//**//*
                JasperHelper.export("excel", fileName, reportFile, request,
                        response, new HashMap(), connection);*//*

        }finally {
            if(connection!=null)connection.close();
        }


    }*/
/*

    @RequestMapping(value = "/showReport1")
    public void showReport1(String loginname, HttpServletRequest request, HttpServletResponse response) throws IOException, JRException, SQLException {

        Connection connection = druidDataSource.getConnection();

        ServletContext context = request.getSession().getServletContext();
        File reportFile = null;
        reportFile = new File("E:\\bi\\report\\optlog.jasper");
        String exportFilePath = "tempPath";
        String fileName = "fileName";

        HashMap map = new HashMap();
        map.put("loginname",loginname);

        */
/* STEP 4 : 输出报表
        *不同输出方式，具体实现在后边注释*//*

        */
/*使用HTML输出，表现为页面直接显示报表*//*

        JasperHelper.showHtml(exportFilePath, reportFile.getPath(), request, response, map, connection);
        */
/*使用PDF输出，表现为出现PDF文件的下载对话框*//*
*/
/*
        JasperHelper.export("pdf", fileName, reportFile, request,
                response, new HashMap(), connection);
        *//*
*/
/*使用EXCEL输出，表现为出现EXCEL文件的下载对话框*//*
*/
/*
        JasperHelper.export("excel", fileName, reportFile, request,
                response, new HashMap(), connection);*//*


        connection.close();

    }




    @RequestMapping(value = "/showReport2",method = RequestMethod.GET)
    public void showReport2(HttpServletRequest request, HttpServletResponse response) throws IOException, JRException {
        List<UserReport> reportList = new ArrayList<UserReport>();
        UserReport report = new UserReport();
        report.setReportname("这是用户报表");
        report.setToday(DateTool.currentDate("yyyy-MM-dd"));
        //report.getImageUrl();
        reportList.add(report);

        JRDataSource datasource = new JRBeanCollectionDataSource(reportList);

        ServletContext context = request.getSession().getServletContext();
        File reportFile = null;
        reportFile = new File(context.getRealPath("/resources/jsperreport/report2.jasper"));
        String exportFilePath = "tempPath";
        String fileName = "fileName";


        */
/* STEP 4 : 输出报表
        *不同输出方式，具体实现在后边注释*//*

        */
/*使用HTML输出，表现为页面直接显示报表*//*

        JasperHelper.showHtml(exportFilePath, reportFile.getPath(), request, response, new HashMap(), datasource);
        */
/*使用PDF输出，表现为出现PDF文件的下载对话框*//*
*/
/*
        JasperHelper.export("pdf", fileName, reportFile, request,
                response, new HashMap(), datasource);
        *//*
*/
/*使用EXCEL输出，表现为出现EXCEL文件的下载对话框*//*
*/
/*
        JasperHelper.export("excel", fileName, reportFile, request,
                response, new HashMap(), datasource);*//*


    }

*/



}